package cn.clazz

/**
  * Created by lzd on 2018/9/5.
  * 在Scala的类中，与类名相同的对象叫做伴生对象，类和伴生对象之间可以相互访问私有的方法和属性
  */
class BanShengObj {
  val a = 123;
  private var b = "hello"
  def pt():Unit={
    println(BanShengObj.c)
  }
}

object BanShengObj{
  private var c = "world"

  def main(args: Array[String]): Unit = {
    val bso = new BanShengObj
    println(bso.a)
    bso.b="hello_"
    println(bso.b)
    bso.pt()

  }
}

object applyDemo{
  def main(args: Array[String]): Unit = {
    //调用Array伴生对象的apply方法
    val array = Array(1,2,3)
    println(array.toBuffer)

    val arr = new Array[Int](3);
    arr(0)=1
    println(arr.toBuffer)

    //数组里面包含了2个null
    val arr2 = new Array(2)
    println(arr2)
  }
}
